Telegram Group & Telegram Channel
SOLID Principles
(part 3)
ثالث مبدأ(LSP) Liskov Substitution Principle

ليسكوف هو اسم العالمة اللي اقترحت هذا المبدأ وهو مبدأ الاستبدال والتعويض اللي يعرفك متى تعمل وراثة من كلاس ثاني ومتى لا وهذا المبدأ يُعتبر تكملة للمبدأ OCP.

‘‘If you have class B inherits from class A then class A should be replaceable by class B without any changes’’

بمعنى اذا كان B يورث من A فإن سلوك الـ client لن يتغير ويظل يعمل بكفاءة اذا استخدمنا B بدلاً من A.

لنفترض لدينا كلاس للطيور وفيها دالتين eat , fly ويوجد كلاسين اخرين(البطريق، النورس) يرثوا من الطيور.

من الطبيعي ان كُل كلاس اصبح يمتلك fly,eat .

لو انشئنا كائن من كلاس الطيور واستخدمنا الدالتين
Bird a = new Bird()
a.fly()
a.eat()

ومن ثَم غيرنا نوع الكائن لكلاس النورس.
Bird a = new Seagull()

فهل سلوك الـ client لن يتغير ويظل يعمل بكفاءة 🤔!

نعم ،لأنه النورس بُكل بساطه يطير ويأكل، إذاً هُنا طبقنا مبدأ ليسكوف.

طيب لو نغير نوع الكائن لكلاس البطريق !
Bird a = new Penguin()

هنا من الطبيعي جداً أن سلوك الـ clint يتغير ولن يعمل بكفاءة لأن البطريق يأكل ولاكن لا يطير ، إذاً هُنا تفشل عملية الوراثة .

طيب ايش الحل🤔؟

موضح في الصورة (2) 🙏.

وأخيراً متى يُستخدم هذا المبدأ ؟!

حينما نجد بأن الكلاسات الفرعية لا تتصرف بنفس الكيفية التي تتصرف بها الكلاسات الرئيسية .

لذلك نحتاج إلى تطبيق هذا المبدأ من أجل أن نضمن أن الكلاسات المُشتقة تستطيع أن تتصرف وكأنها كلاس رئيسي دون أن يؤثر على سلوك الـ client.

يتبع..



tg-me.com/beginprogrammer/635
Create:
Last Update:

SOLID Principles
(part 3)
ثالث مبدأ(LSP) Liskov Substitution Principle

ليسكوف هو اسم العالمة اللي اقترحت هذا المبدأ وهو مبدأ الاستبدال والتعويض اللي يعرفك متى تعمل وراثة من كلاس ثاني ومتى لا وهذا المبدأ يُعتبر تكملة للمبدأ OCP.

‘‘If you have class B inherits from class A then class A should be replaceable by class B without any changes’’

بمعنى اذا كان B يورث من A فإن سلوك الـ client لن يتغير ويظل يعمل بكفاءة اذا استخدمنا B بدلاً من A.

لنفترض لدينا كلاس للطيور وفيها دالتين eat , fly ويوجد كلاسين اخرين(البطريق، النورس) يرثوا من الطيور.

من الطبيعي ان كُل كلاس اصبح يمتلك fly,eat .

لو انشئنا كائن من كلاس الطيور واستخدمنا الدالتين
Bird a = new Bird()
a.fly()
a.eat()

ومن ثَم غيرنا نوع الكائن لكلاس النورس.
Bird a = new Seagull()

فهل سلوك الـ client لن يتغير ويظل يعمل بكفاءة 🤔!

نعم ،لأنه النورس بُكل بساطه يطير ويأكل، إذاً هُنا طبقنا مبدأ ليسكوف.

طيب لو نغير نوع الكائن لكلاس البطريق !
Bird a = new Penguin()

هنا من الطبيعي جداً أن سلوك الـ clint يتغير ولن يعمل بكفاءة لأن البطريق يأكل ولاكن لا يطير ، إذاً هُنا تفشل عملية الوراثة .

طيب ايش الحل🤔؟

موضح في الصورة (2) 🙏.

وأخيراً متى يُستخدم هذا المبدأ ؟!

حينما نجد بأن الكلاسات الفرعية لا تتصرف بنفس الكيفية التي تتصرف بها الكلاسات الرئيسية .

لذلك نحتاج إلى تطبيق هذا المبدأ من أجل أن نضمن أن الكلاسات المُشتقة تستطيع أن تتصرف وكأنها كلاس رئيسي دون أن يؤثر على سلوك الـ client.

يتبع..

BY بدايه مبرمج


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/beginprogrammer/635

View MORE
Open in Telegram


بدايه مبرمج Telegram | DID YOU KNOW?

Date: |

Spiking bond yields driving sharp losses in tech stocks

A spike in interest rates since the start of the year has accelerated a rotation out of high-growth technology stocks and into value stocks poised to benefit from a reopening of the economy. The Nasdaq has fallen more than 10% over the past month as the Dow has soared to record highs, with a spike in the 10-year US Treasury yield acting as the main catalyst. It recently surged to a cycle high of more than 1.60% after starting the year below 1%. But according to Jim Paulsen, the Leuthold Group's chief investment strategist, rising interest rates do not represent a long-term threat to the stock market. Paulsen expects the 10-year yield to cross 2% by the end of the year. A spike in interest rates and its impact on the stock market depends on the economic backdrop, according to Paulsen. Rising interest rates amid a strengthening economy "may prove no challenge at all for stocks," Paulsen said.

Launched in 2013, Telegram allows users to broadcast messages to a following via “channels”, or create public and private groups that are simple for others to access. Users can also send and receive large data files, including text and zip files, directly via the app.The platform said it has more than 500m active users, and topped 1bn downloads in August, according to data from SensorTower.بدايه مبرمج from ua


Telegram بدايه مبرمج
FROM USA